#include <stdio.h>
#include <string.h>
bool hash[8000000];
int judge(int n)
{
	while(n)
	{
		if(n%9==0) return 0;
		n= n/9;
	}
	return 1;
}
int main()
{
	int t,len;
	char str[1000001];
	scanf("%d",&t);
	getchar();
	while(t--)
	{
		memset(hash,0,sizeof(hash));
		gets(str);
		len = strlen(str);
		for(int i = 1;i<=6;i++)
		{
		//printf("*****\n");	
			for(int j = 0;j<len-i+1;j++)
			{
				int temp=0;
				for(int k = 0;k<i;k++)
				{
					temp = temp*9+str[j+k]-'A'+1;
				}
				hash[temp]=1;
			}
		}
		//printf("****\n");
		char ans[100];
		int top = 0; 
		for(int i=1;;i++)
		{
			//printf("******\n");
			if(!hash[i]&&judge(i))
			{
				printf("i = %d\n",i);
				while(i)
				{
					ans[top++] = i%9+'A'-1;
					i = i/9;
				}
				break;
			}
		}
		for(int i = top-1;i>=0;i--)
		{
			printf("%c",ans[i]);
		}
		printf("\n");
	}
} 
